Authoritative LaTeX
1 Quick Intro
On May 1st, 2015, Authorea deployed a new backend for its LaTeX input language, teaming up with the ambitious LaTeXML project, which strives to offer a full reimplementation of TeX with targeted generation of web-first manuscripts, supporting HTML5 and ePub.
To enable LaTeXML, select the following option in your article page:
Settings (topbar Gear icon) Advanced settings More Preferences LaTeX Support LaTeXML
In this article you can find an overview of some of our new high impact authoring features.
2 Code Listings
We will be illustrating all of our examples with code listings in this tutorial, so let’s first show how to set them up.
An example setup which you can add to your header.tex
file is:
Useful to keep in mind: definitions in your header.tex
file are global to your article, while macros
introduced in a paragraph are only local to that paragraph. That applies even to global commands such as \gdef
, as Authorea processes each paragraph
independently of its surroundings.
3 Basic Macros
As mentioned above, only definitions placed in header.tex
are global for your entire article. You can use all
flavors of TeX’s definitions (\def
, \edef
, \xdef
, \gdef
, \newcommand
, \rewnewcommand
, …) to your liking.
If you want to discuss a notable term, such as LaTeXML, you may want to define a handy macro which:
- 1.
Links to the term’s Wikipedia page
- 2.
Is available in your entire document (define it in
header.tex
) - 3.
Flexibly figures out if it needs a trailing space or not11one of TeX’s original weaknesses with its macros
- 4.
Is easier to write than the term’s full name
Here is one way you can achieve that, with the entities used in this tutorial:
4 Text Styles
4.1 Fonts
\normalfont (default) |
Authorea |
---|---|
\rmfamily |
Authorea |
\sffamily |
Authorea |
\ttfamily |
Authorea |
4.2 Sizes
\Huge |
Authorea |
---|---|
\huge |
Authorea |
\LARGE |
Authorea |
\Large |
Authorea |
\large |
Authorea |
\normalsize (default) |
Authorea |
\small |
Authorea |
\footnotesize |
Authorea |
\scriptsize |
Authorea |
\tiny |
Authorea |
4.3 Text Color
If you want the extended color set, you will need to add \usepackage[dvipsnames,tables]{xcolor}
to
your header.tex
file.
The 68 standard colors known to dvips are (in alphabetical order):
Apricot
Aquamarine
Bittersweet
Black
Blue
BlueGreen
BlueViolet
BrickRed
Brown
BurntOrange
CadetBlue
CarnationPink
Cerulean
CornflowerBlue
Cyan
Dandelion
DarkOrchid
Emerald
ForestGreen
Fuchsia
Goldenrod
Gray
Green
GreenYellow
JungleGreen
Lavender
LimeGreen
Magenta
Mahogany
Maroon
Melon
MidnightBlue
Mulberry
NavyBlue
OliveGreen
Orange
OrangeRed
Orchid
Peach
Periwinkle
PineGreen
Plum
ProcessBlue
Purple
RawSienna
Red
RedOrange
RedViolet
Rhodamine
RoyalBlue
RoyalPurple
RubineRed
Salmon
SeaGreen
Sepia
SkyBlue
SpringGreen
Tan
TealBlue
Thistle
Turquoise
Violet
VioletRed
White
WildStrawberry
Yellow
YellowGreen
YellowOrange
Use them via {\color{ColorName} your text}
.
5 Definitions, Theorems, Lemmas and more
AMS-flavored LaTeX introduces a flexible language for declaring custom types of environments. It has long been the weapon of choice for declaring mathematical statements, for example:
Theorem 5.1 (Pythagoras).
Suppose are the side-lengths of a right triangle.
Then .
Proof.
Proof is left as an exercise to the reader. ∎
6 Tables
6.1 Merging rows and columns
- •
To merge columns:
\multicolumn{cell count}{layout}{content}
- •
To merge rows:
\multirow{cell count}{layout}{content}
Example:
Table cheat sheet | ||
---|---|---|
Horizontal line | \hline |
underlines current table row |
Column types | l |
left |
c |
center | |
r |
right | |
p{'width'} |
custom width, aligned top | |
m{'width'} |
custom width, aligned middle22requires array.sty | |
b{'width'} |
custom width, aligned bottom33requires array.sty | |
Borders | none | default |
| |
single, as in l| |
|
|| |
double, as in l||c |
|
Alignment | & | separates columns |
End of line | \\ |
new table row |
newline |
new line within cell |
6.2 Advanced Table Borders
Sometimes it is helpful to be able to provide partial border specifications, for either rows or columns.
- •
\cline{i-j}
provides a partial bottom border between columnsi
andj
of the current row. - •
A combined use of
\multicolumn
and\multirow
can build a partial vertical border.
Here is one illustrating example:
Primes | ||||||
---|---|---|---|---|---|---|
2 | 3 | 5 | 7 | |||
Powers | 504 | 3 | 2 | 0 | 1 | |
540 | 2 | 3 | 1 | 0 | ||
Powers | gcd | 2 | 2 | 0 | 0 | min |
lcm | 3 | 3 | 1 | 1 | max |
6.3 Advanced Table Colors
6.3.1 Row Colors
In Section 4.3 we showed the extended set of colors available through the
xcolor.sty
package. For
tables, it is also useful to have control over the background color of individual rows. One can set row
colors via the aptly named \rowcolor
macro, and set alternating colors for rows using
the \rowcolors
macro, starting
at a particular row offset. Here is an example:
An Example of Row Colors |
---|
Heading can be White |
Green |
Lighter Green |
Green |
Lighter Green |
6.3.2 Backgrounds for Individual Cells
Setting the background color of a column can be achieved indirectly via
the \newcolumntype
macro,
which defines a new column type. That new type could be based on an existing column specification (e.g. the
”centered” c
), with a modified
background color via the \columncolor
macro. In case a row or column background
color needs to be overridden, the cell-specific \cellcolor
macro comes to the rescue. Here is an
illustrating example that puts all of these techniques together:
Comparison of Sorting Algorithms | ||||
Name | Performance | Memory | ||
Best | Average | Worst | ||
Quicksort | ||||
Merge Sort | worst case | |||
In-place merge Sort | – | – | 1 |
Source for the tabular data: http://en.wikipedia.org/wiki/Sorting_algorithm
7 Layout Directives
7.1 General Layout
7.2 Tables and Listings
Authorea supports figures as separate text blocks, so you should never have to
write \begin{figure}
in your
documents. However, listings and tables are perfectly acceptable. In fact, you could be curious to find out
the technique which we use here for aligning our listings and tables in two horizontal columns. The relevant
snippet is:
The reason we use \begin{figure}[h!]
here is to explicitly order TeX to
position the figure as close as possible to the current insertion point.
7.3 Note on Margins
If you are very serious about producing beautiful HTML and PDF, you will sooner or later need to understand how margins work and how they differ between the two paradigms. As long as you are not using advanced features, Authorea can automate all those considerations for you, but the moment you want beautiful side-by-side tables, you may be forced to become painfully aware of the PDF-related float widths and margin sizes.
Best to remember: If you don’t want to know anything about margins and just
want to disseminate your preprint to colleagues, use \usepackage{fullpage}
which disables page margins.
Otherwise, try to design your minipage environments so that they never sum up to over 0.9\textwidth
and ideally 0.8\textwidth
, to avoid unpleasant overflows. There are
other TeX tricks one can employ but we recommend heavily against indulging in low-level fine-tuning, as it is both a time sink
and a great potential source of frustration.
7.4 Note on Vertical Overflow
HTML pages are designed to be infinitely scrollable. However, this is clearly
not the case in printable PDF documents, and if you want your tables to display nicely on a paper page you
need to take precautions against vertical overflow early. A simple solution is to use the {longtable}
environment instead of {tabular}
, which will auto-break the
pages for you, when exporting to PDF.
7.5 Note on Format-specific Directives
In few unfortunate cases the investment of writing format-independent LaTeX simply isn’t worth
the result. For example, it may be very easy to align two {minipage}
blocks next to each other in HTML, but extremely
painfull to fit them on the page in PDF. To achieve a delightful outcome in both formats in such cases, it may
be needed to resort to platform-specific directives. LaTeXML offers support for this distinction using its own conditional operator:
\iflatexml
.
Here is an example setup that you can add to your header.tex
file:
and then use it to specify PDF-only line-breaks for your {minipage}
blocks:
The most common use of PDF-specific directives would likely remain the need for hard page breaks:
Last, but very importantly, please be reminded that at Authorea we strongly advise against attempting to do low-level tweaking of your document, both because of the numerous dragons lurking on that road, and because the Authorea editing experience is much more rewarding in both speed and writing enjoyment.
8 LaTeX Programming? Only if you really really have to…
8.1 Generating a multiplication table
To illustrate why you should avoid doing any low-level TeX programming yourself44Unless you really know what you are doing, and you really must here is an example of the hoops you need to jump through to typeset the multiplication table from five to nine:
8.2 Generating a Christmass Caroll
In a classic argument about whether a naive approach to counting the words of a TeX manuscript could be successful, David Carlisle provided the following snippet as an example:
Source: http://ctan.org/pkg/xii
Clearly, a naive approach may find a handful, if any words, as this TeX program is obfuscated to a degree of infamy. In fact, it is a demonstration that the only correct way of counting words in a LaTeX document is by inspecting the final produced output, be it a PDF or HTML document. Authorea is one of the few tools that correctly approaches word count and can tackle this example successfully, with a click of a button.
You can enjoy the full carol here.